﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using CustomsSystem.BLL;
using CustomsSystem.Model;

namespace WEB.Code
{
    public partial class Index_Job : System.Web.UI.Page
    {
        DataSet ds = new DataSet();
        JobManage JM = new JobManage();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ds = JM.GetAllList();
                GridView1.DataSource = ds;
                GridView1.DataBind();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("AddJob.aspx");
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string EMPNO = Convert.ToString(GridView1.DataKeys[e.RowIndex].Value);
            JobManage JM = new JobManage();
            if (JM.ExUser(EMPNO) <= 0)
            {
                if (JM.Delete(EMPNO))
                {
                    Response.Write("<Script>alert('删除成功!')</script>");

                    ds = JM.GetAllList();
                    GridView1.DataSource = ds;
                    GridView1.DataBind();
                }
                else
                {
                    Response.Write("<Script>alert('删除失败!')</script>");
                    return;
                }
            }
            else
            {
                Response.Write("<Script>alert('该岗位还有员工,请处理好员工再删除岗位!')</script>");
                return;
            }
        }
        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.SelectedIndex = e.NewEditIndex;
            string jobno = GridView1.SelectedRow.Cells[0].Text;
            Session["jobno"] = jobno;
            Response.Redirect("ChanceJob.aspx?jobno="+jobno);
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //如果是绑定数据行         
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
                {
                    ((LinkButton)e.Row.Cells[3].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除：\"" + e.Row.Cells[1].Text + "\"职位吗?')");
                }
            } 
        }
    }
}